package com.weishu.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.weishu.common.core.utils.StringUtils;
import com.weishu.core.entity.CfContract;
import com.weishu.core.mapper.CfContractMapper;
import com.weishu.core.service.ICfContractService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zgx
 * @since 2021-10-19
 */
@Service
public class CfContractServiceImpl extends ServiceImpl<CfContractMapper, CfContract> implements ICfContractService {
    @Resource
    private ICfContractService iCfContractService;

    @Resource
    private CfContractMapper tCfContractMapper;

    @Override
    public PageInfo<CfContract> getList(Integer pageNum, Integer pageSize, CfContract cfContract) {
        QueryWrapper<CfContract> queryWrapper = new QueryWrapper<>();
        if(cfContract!=null){
            //判断租户姓名不为空
            if(!StringUtils.isEmpty(cfContract.getTenantName())){
                queryWrapper.like("tenant_name",cfContract.getTenantName());
            }

            //判断房源类型不为空
            if(Objects.nonNull(cfContract.getSignType())){
                queryWrapper.eq("sign_type",cfContract.getSignType());
            }

            //判断电话号不为空
            if(!StringUtils.isEmpty(cfContract.getTenantPhone())){
                queryWrapper.eq("tenant_phone",cfContract.getTenantPhone());
            }

            //判断小区名不为空
            if(!StringUtils.isEmpty(cfContract.getPremiseName())){
                queryWrapper.like("premise_name",cfContract.getPremiseName());
            }

            //判断起租日期不为空
            if(Objects.nonNull(cfContract.getStartDate())){
                queryWrapper.gt("start_date",cfContract.getStartDate());
            }
        }
        PageHelper.startPage(pageNum,pageSize);
        List<CfContract> list = iCfContractService.list(queryWrapper);
        PageInfo<CfContract> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public CfContract selectTCfContractById(Long id) {
        return tCfContractMapper.selectTCfContractById(id);
    }


    @Override
    public List<CfContract> selectTCfContractList(CfContract tCfContract) {
        return tCfContractMapper.selectTCfContractList(tCfContract);
    }
}
